package com.shamar.blog.enums;

import org.apache.commons.lang3.ArrayUtils;

public enum ChannelPayStatus {

    FAIL(0, "支付失败"),
    SUCCESS(1, "支付成功"),
    PROCESSING(2, "支付中"),
    REFUND(3, "转入退款"),
    NOTPAY(4, "未支付"),
    CLOSED(5, "已关闭"),
    REVOKED(6, "已撤销"),
    REFUSE(7, "已拒绝"),
    REFUSEING(8, "拒绝中"),
    CANCEL(9, "已取消"),

    ;

    private Integer value;
    private String desc;

    ChannelPayStatus(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    //不应该存在的状态
    private static ChannelPayStatus[] shouldNotExistList = {REFUND, REVOKED, REFUSE, REFUSEING, CANCEL};

    /**
     * 判断支付单不应该存在的状态
     * @param status
     * @return
     */
    public static Boolean shouldNotExist(ChannelPayStatus status) {
        return ArrayUtils.contains(shouldNotExistList, status);
    }

    public static ChannelPayStatus valueOf(int value) {

        for (ChannelPayStatus type : ChannelPayStatus.values()) {
            if (type.getValue() == value) {
                return type;
            }
        }
        return null;
    }

    public static boolean checkClosedAndFailedStatus(Integer payStatus) {
        return ChannelPayStatus.CLOSED.getValue().equals(payStatus) || ChannelPayStatus.FAIL.getValue().equals(payStatus);
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
